/*
 * JTalkerFrontSettings.java
 *
 * Created on 27. Oktober 2003, 11:11
 */

package com.jtalker.client;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Enumeration;

import javax.swing.AbstractButton;
import javax.swing.AbstractListModel;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/** This class represents the property dialog */
public class JTalkerFrontSettings extends JFrame {
	private static final long serialVersionUID = 1L;
	private JTalkerClientFront parent = null;
	private boolean onInit = true;

	/** Creates new form JTalkerFrontSettings */
	public JTalkerFrontSettings(JTalkerClientFront parent) {
		this.parent = parent;
		this.initComponents();
		this.setupElements();
		this.setSize(500, 320);
		this.jListPropertyPages.setSelectedIndex(0);
		this.showPropertyPanel(0);
		this.setLocationRelativeTo(parent);
		this.getRootPane().setDefaultButton(this.jButtonOK);
		this.onInit = false;
	}

	/**
	 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
	 * content of this method is always regenerated by the Form Editor.
	 */
	private void initComponents() {
		jPanelBottom = new JPanel();
		jButtonOK = new JButton();
		jButtonCancel = new JButton();
		jPanelCenter = new JPanel();
		jSplitPaneProperty = new JSplitPane();
		jScrollPaneProperty = new JScrollPane();
		jListPropertyPages = new JList();
		jPanelContent = new JPanel();
		jPanelPropsAccount = new JPanel();
		jLabelUserName = new JLabel();
		jTextFieldUserName = new JTextField();
		jButton3 = new JButton();
		jLabelPassword = new JLabel();
		jPasswordFieldPasswd = new JPasswordField();
		jCheckBoxSavePasswd = new JCheckBox();
		jCheckBoxUseSSL = new JCheckBox();
		jPanelPropsServer = new JPanel();
		jLabelServerName = new JLabel();
		jTextFieldServerIP = new JTextField();
		jLabelServerPort = new JLabel();
		jLabelAppsBrowser = new JLabel();
		jLabelAppsEMailClient = new JLabel();
		jTextFieldAppsBrowser = new JTextField();
		jTextFieldAppsEMailClient = new JTextField();
		jTextFieldServerPort = new JTextField();
		jButton4 = new JButton();
		jPanelPropsApps = new JPanel();
		jPanelNotificationApps = new JPanel();
		jPanelLookAndFeel = new JPanel();
		jPanelPlugins = new JPanel();
		jLabelPluginDir = new JLabel();
		jTextFieldPluginDir = new JTextField();
		cl = ResourceAnchor.class.getClassLoader();

		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				windowClosing(null);
			}
		});

		jButtonOK.setText("OK");
		jButtonOK.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				saveConfiguration(evt);
			}
		});

		jPanelBottom.add(jButtonOK);

		jButtonCancel.setText("Cancel");
		jButtonCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				closeWindow(evt);
			}
		});
		jPanelBottom.add(jButtonCancel);
		this.getContentPane().add(jPanelBottom, BorderLayout.SOUTH);

		jPanelCenter.setLayout(new BorderLayout());
		jListPropertyPages.setModel(new AbstractListModel() {
			private static final long serialVersionUID = 1L;
			String[] properties = { "Login", "Server", "Apps", "Notification", "Look", "Plugins" };

			public int getSize() {
				return properties.length;
			}

			public Object getElementAt(int i) {
				return properties[i];
			}
		});

		jListPropertyPages.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent evt) {
				listPropertyChanged(evt);
			}
		});

		jListPropertyPages.setCellRenderer(new MyListCellRenderer());
		jScrollPaneProperty.setViewportView(jListPropertyPages);
		jSplitPaneProperty.setLeftComponent(jScrollPaneProperty);

		jPanelContent.setLayout(new BoxLayout(jPanelContent, BoxLayout.Y_AXIS));
		// //////////////// Account Props /////////////////////////////
		jPanelPropsAccount.setLayout(null);

		jLabelUserName.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelUserName.setText("User Name:");
		jPanelPropsAccount.add(jLabelUserName);
		jLabelUserName.setBounds(0, 10, 110, 30);

		jTextFieldUserName.setToolTipText("Your JTalker user name");
		jPanelPropsAccount.add(jTextFieldUserName);
		jTextFieldUserName.setBounds(120, 10, 123, 30);

		/*
		 * jButton3.setText("Create New Account..."); jButton3.setEnabled(false);
		 * jButton3.setToolTipText("Lets create you a new JTalker Account"); jButton3.setMargin(new Insets(2, 1, 2, 1));
		 * jButton3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) {
		 * jButton3ActionPerformed(evt); } });
		 * 
		 * jPanelPropsAccount.add(jButton3); jButton3.setBounds(30, 130, 160, 30);
		 */

		jLabelPassword.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelPassword.setText("User Password:");
		jPanelPropsAccount.add(jLabelPassword);
		jLabelPassword.setBounds(0, 50, 110, 30);

		jPanelPropsAccount.add(jPasswordFieldPasswd);
		jPasswordFieldPasswd.setBounds(120, 50, 123, 30);

		jCheckBoxSavePasswd.setSelected(true);
		jCheckBoxSavePasswd.setText("Save Password");
		jCheckBoxSavePasswd.setToolTipText(" Saves Your password in the config file");
		jPanelPropsAccount.add(jCheckBoxSavePasswd);
		jCheckBoxSavePasswd.setBounds(120, 90, 120, 26);

		jPanelContent.add(jPanelPropsAccount);

		// //////////////// Server Props /////////////////////////////
		jPanelPropsServer.setLayout(null);

		jLabelServerName.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelServerName.setText("Server Name:");
		jPanelPropsServer.add(jLabelServerName);
		jLabelServerName.setBounds(0, 10, 110, 30);

		jTextFieldServerIP.setToolTipText("Servers IP-Adress");
		jPanelPropsServer.add(jTextFieldServerIP);
		jTextFieldServerIP.setBounds(120, 10, 123, 30);

		jLabelServerPort.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelServerPort.setText("Server Port:");
		jPanelPropsServer.add(jLabelServerPort);
		jLabelServerPort.setBounds(0, 50, 110, 30);

		jTextFieldServerPort.setToolTipText("Servers Port number");
		jPanelPropsServer.add(jTextFieldServerPort);
		jTextFieldServerPort.setBounds(120, 50, 123, 30);

		/*
		 * jButton4.setText("Test"); jButton4.setToolTipText("Tests if a JTalker server is available");
		 * jButton4.setMargin(new Insets(2, 1, 2, 1)); jButton4.addActionListener(new ActionListener() { public void
		 * actionPerformed(ActionEvent evt) { jButton4ActionPerformed(evt); } });
		 * 
		 * jPanelPropsServer.add(jButton4); jButton4.setBounds(33, 100, 160, 30);
		 */

		jCheckBoxUseSSL.setSelected(true);
		jCheckBoxUseSSL.setText("Use SSL");
		jCheckBoxUseSSL.setToolTipText("Use secure connection to server");
		jPanelPropsServer.add(jCheckBoxUseSSL);
		jCheckBoxUseSSL.setBounds(120, 90, 120, 26);
		jPanelPropsServer.add(jCheckBoxUseSSL);

		jPanelContent.add(jPanelPropsServer);

		// //////////////// Applications Props /////////////////////////////
		jPanelPropsApps.setLayout(null);

		jLabelAppsBrowser.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelAppsBrowser.setText("Web Browser:");
		jPanelPropsApps.add(jLabelAppsBrowser);
		jLabelAppsBrowser.setBounds(0, 10, 110, 30);

		jTextFieldAppsBrowser.setToolTipText("Full path to Your favourite browser");
		jPanelPropsApps.add(jTextFieldAppsBrowser);
		jTextFieldAppsBrowser.setBounds(120, 10, 123, 30);
		jTextFieldAppsBrowser.setText("mozilla");

		jLabelAppsEMailClient.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelAppsEMailClient.setText("Mail Client:");
		jPanelPropsApps.add(jLabelAppsEMailClient);
		jLabelAppsEMailClient.setBounds(0, 50, 110, 30);

		jTextFieldAppsEMailClient.setToolTipText("Full path to Your favourite e-mail client");
		jTextFieldAppsEMailClient.setText("kmail");
		jPanelPropsApps.add(jTextFieldAppsEMailClient);
		jTextFieldAppsEMailClient.setBounds(120, 50, 123, 30);

		jPanelContent.add(jPanelPropsApps);

		// //////////////// Notification Props /////////////////////////////
		jPanelNotificationApps.setLayout(new GridLayout(2, 1));
		buttonGroupNotification = new ButtonGroup();
		// buttonGroupNotificationChat = new ButtonGroup();
		jPanelUserList = new JPanel();
		jLabelUserListInfo = new JLabel();
		jRadioButtonUserListNone = new JRadioButton();
		jRadioButtonUserListToFront = new JRadioButton();
		jRadioButtonUserListNotiBox = new JRadioButton();
		jRadioButtonUserListBeep = new JRadioButton();
		/*
		 * jPanelCHATWINDOW = new JPanel(); jRadioButtonCHATWINDOWNONE = new JRadioButton(); jRadioButtonCHATWINDOWBEEP
		 * = new JRadioButton();
		 */

		jPanelUserList.setLayout(new GridLayout(5, 0));

		jPanelUserList.setBorder(new TitledBorder("New Mail Notification (Main Window)"));
		jLabelUserListInfo.setBackground(SystemColor.info);
		jLabelUserListInfo.setText("Occures only, if no chat window is open for affected user.");
		jLabelUserListInfo.setOpaque(true);
		jPanelUserList.add(jLabelUserListInfo);

		buttonGroupNotification.add(jRadioButtonUserListNone);
		jRadioButtonUserListNone.setText("None (only an envelope icon)");
		jPanelUserList.add(jRadioButtonUserListNone);

		buttonGroupNotification.add(jRadioButtonUserListToFront);
		jRadioButtonUserListToFront.setText("Bring main window to front (get focus)");
		jPanelUserList.add(jRadioButtonUserListToFront);

		buttonGroupNotification.add(jRadioButtonUserListNotiBox);
		jRadioButtonUserListNotiBox.setText("Show a nice notification box (in background)");
		jPanelUserList.add(jRadioButtonUserListNotiBox);

		buttonGroupNotification.add(jRadioButtonUserListBeep);
		jRadioButtonUserListBeep.setText("Beep");
		jPanelUserList.add(jRadioButtonUserListBeep);

		jPanelNotificationApps.add(jPanelUserList);
		jPanelUserList.getAccessibleContext().setAccessibleName("Main Window");

		/*
		 * jPanelCHATWINDOW.setLayout(new GridLayout(5, 0));
		 * 
		 * jPanelCHATWINDOW.setBorder(new TitledBorder("New Mail Notification (Chat Window)" ));
		 * buttonGroupNotificationChat.add(jRadioButtonCHATWINDOWNONE); jRadioButtonCHATWINDOWNONE.setText("None");
		 * jPanelCHATWINDOW.add(jRadioButtonCHATWINDOWNONE);
		 * 
		 * buttonGroupNotificationChat.add(jRadioButtonCHATWINDOWBEEP); jRadioButtonCHATWINDOWBEEP.setText("Beep");
		 * jPanelCHATWINDOW.add(jRadioButtonCHATWINDOWBEEP);
		 * 
		 * jPanelNotificationApps.add(jPanelCHATWINDOW);
		 */
		jPanelContent.add(jPanelNotificationApps);

		// //////////////// Look And Feel Props /////////////////////////////
		jPanelLookAndFeel.setLayout(new GridLayout(2, 1));
		jPanelLookPlafs = new JPanel();
		jComboBoxAllLooks = new JComboBox();
		jPanelLookColors = new JPanel();
		jLabelLookBGColor = new JLabel();
		jButtonLookBGColor = new JButton();
		jLabelLookTXColor = new JLabel();
		jButtonLookTXColor = new JButton();
		jButtonPlugins = new JButton();
		jButtonPluginDir = new JButton();

		jPanelLookPlafs.setBorder(new TitledBorder("Look And Feel"));
		jComboBoxAllLooks.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				switchLookAndFeel(evt);
			}
		});

		jPanelLookPlafs.add(jComboBoxAllLooks);
		jPanelLookAndFeel.add(jPanelLookPlafs);

		jPanelLookColors.setLayout(new GridLayout(2, 2));
		jPanelLookColors.setBorder(new TitledBorder("Colors"));
		jLabelLookBGColor.setText("Chat Background Color:");
		jPanelLookColors.add(jLabelLookBGColor);

		jButtonLookBGColor.setText("Color...");
		jButtonLookBGColor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				selectBGColor(evt);
			}
		});

		jPanelLookColors.add(jButtonLookBGColor);

		jLabelLookTXColor.setText("Chat Text Color:");
		jPanelLookColors.add(jLabelLookTXColor);

		jButtonLookTXColor.setText("Color...");
		jButtonLookTXColor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				selectTXColor(evt);
			}
		});

		jPanelLookColors.add(jButtonLookTXColor);

		jPanelLookAndFeel.add(jPanelLookColors);

		jPanelContent.add(jPanelLookAndFeel);

		// //////////////// Applications Props /////////////////////////////
		jPanelPlugins.setLayout(null);

		jLabelPluginDir.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelPluginDir.setText("Plugin Dir:");
		jLabelPluginDir.setBounds(0, 10, 110, 30);
		jPanelPlugins.add(jLabelPluginDir);

		jTextFieldPluginDir.setToolTipText("Full path to the plugin directory");
		jTextFieldPluginDir.setBounds(120, 10, 160, 30);
		jTextFieldPluginDir.setText(System.getProperty("user.home") + File.separator + "jt_plugins");
		jTextFieldPluginDir.setEditable(false);
		jPanelPlugins.add(jTextFieldPluginDir);

		jButtonPlugins.setBounds(120, 50, 160, 30);
		jButtonPlugins.setText("Plugin Overview");
		jButtonPlugins.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				clickPluginsOverview(evt);
			}
		});
		jPanelPlugins.add(jButtonPlugins);

		jButtonPluginDir.setBounds(285, 10, 30, 30);
		jButtonPluginDir.setText("...");
		jButtonPluginDir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				selectPluginDir(evt);
			}
		});
		jPanelPlugins.add(jButtonPluginDir);
		jPanelContent.add(jPanelPlugins);

		// //////////////////////////////////////////////////////////////////

		jSplitPaneProperty.setRightComponent(jPanelContent);
		jPanelCenter.add(jSplitPaneProperty, BorderLayout.CENTER);
		this.getContentPane().add(jPanelCenter, BorderLayout.CENTER);

		this.setTitle("JTalker Configuration");
		this.pack();
	}

	private void closeWindow(ActionEvent evt) {
		// CANCEL
		this.setupElements();
		this.dispose();
	}

	private void jButton4ActionPerformed(ActionEvent evt) {
		// Test if server available
	}

	private void jButton3ActionPerformed(ActionEvent evt) {
		// Create Account
	}

	private void clickPluginsOverview(ActionEvent evt) {
		// Show Plug-in Overview
		if (this.parent.myPluginsInfoDialog == null){
			this.parent.myPluginsInfoDialog = new JTalkerClientPluginsInfo(this.parent);
		}
		if (this.parent.myPluginsInfoDialog.updatePluginList(this.jTextFieldPluginDir.getText())){
			this.parent.myPluginsInfoDialog.setVisible(true);
		}
	}

	private void selectPluginDir(ActionEvent evt) {
		// Select Plugin Dir
		JFileChooser fc = new JFileChooser();
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		fc.setCurrentDirectory(new File(this.jTextFieldPluginDir.getText()));

		int returnVal = fc.showOpenDialog(this);

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			// Open File
			File file = fc.getSelectedFile();
			String tmpFilename = file.getAbsolutePath();

			this.jTextFieldPluginDir.setText(tmpFilename + File.separator);
		}
	}

	private void listPropertyChanged(ListSelectionEvent evt) {
		// Add your handling code here:
		this.showPropertyPanel(this.jListPropertyPages.getSelectedIndex());
	}

	private void saveConfiguration(ActionEvent evt) {
		// OK
		String user = this.jTextFieldUserName.getText();
		String passwd = new String(this.jPasswordFieldPasswd.getPassword());
		String serverIP = this.jTextFieldServerIP.getText();
		String serverPort = this.jTextFieldServerPort.getText();
		String browser = this.jTextFieldAppsBrowser.getText();
		String mailClient = this.jTextFieldAppsEMailClient.getText();
		int notificationType = 0;
		String guiTextColor = JTalkerClient.getColorAsString(this.jButtonLookTXColor.getBackground());
		String guiBgColor = JTalkerClient.getColorAsString(this.jButtonLookBGColor.getBackground());
		String guiPlaf = (String) this.jComboBoxAllLooks.getSelectedItem();
		String plugindir = this.jTextFieldPluginDir.getText();

		for (Enumeration<AbstractButton> e = this.buttonGroupNotification.getElements(); e.hasMoreElements();) {
			if (((JRadioButton) e.nextElement()).isSelected()) {
				break;
			}
			notificationType++;
		}

		try {
			this.parent.theClient.serverName = serverIP;
			this.parent.theClient.portNum = Integer.parseInt(serverPort);
			this.parent.theClient.userName = user;
			this.parent.theClient.userPasswd = passwd;
			this.parent.theClient.defaultBrowser = browser;
			this.parent.theClient.defaultMailer = mailClient;
			this.parent.theClient.newMailNotificationType = notificationType;
			this.parent.theClient.guiTextColor = guiTextColor;
			this.parent.theClient.guiBgColor = guiBgColor;

			if (this.jCheckBoxUseSSL.isSelected()) {
				this.parent.theClient.useSSL = true;
				// TODO: Only by using strong certs (from keystore)
				/*
				 * // Check for keystore this.parent.theClient.useSSL = false; String keyStore = null;
				 * 
				 * 
				 * try { keyStore = System.getProperty("javax.net.ssl.trustStore"); if(keyStore != null) { boolean
				 * keyStoreOK = new File(keyStore).canRead(); if(!keyStoreOK) { System.err.println("*** Can't read " +
				 * keyStore); } else this.parent.theClient.useSSL = true; } } catch (Exception _e) {
				 * System.err.println("*** Error: " + _e.toString()); }
				 * 
				 * if(!this.parent.theClient.useSSL) { JOptionPane.showMessageDialog(null, "Keystore not available:\n" +
				 * keyStore, "Can't use SSL", JOptionPane.ERROR_MESSAGE); return; }
				 */
			} else {
				this.parent.theClient.useSSL = false;
			}
			if (!guiPlaf.equals(this.parent.theClient.guiPlaf)) {
				// Set new LnF
				this.parent.theClient.guiPlaf = guiPlaf;
				try {
					UIManager.setLookAndFeel((String) this.jComboBoxAllLooks.getSelectedItem());
					SwingUtilities.updateComponentTreeUI(this.parent);
				} catch (Exception e) {
					System.out.println("*** Can't set Look'n'Feel!");
				}
			}

			this.parent.theClient.pluginDir = plugindir;
			this.parent.loadAllPlugins();

			// OK, lets save all
			if (this.jCheckBoxSavePasswd.isSelected()) {
				this.parent.theClient.savePassword = true;
			} else {
				this.parent.theClient.savePassword = false;
			}
			this.parent.theClient.saveSettings();

		} catch (Exception e) {
			this.parent.theClient.portNum = 4444;
			System.err.println("*** Can't set properties: " + e.toString());
		}

		this.dispose();
	}

	/** Select Text Color */
	private void selectTXColor(ActionEvent evt) {
		Color newColor = JColorChooser.showDialog(this.jButtonLookTXColor, "Choose a custom color",
				this.jButtonLookTXColor.getBackground());
		if (newColor != null) {
			this.jButtonLookTXColor.setBackground(newColor);
		}
	}

	/** Select BG Color */
	private void selectBGColor(ActionEvent evt) {
		Color newColor = JColorChooser.showDialog(this.jButtonLookBGColor, "Choose a custom color",
				this.jButtonLookBGColor.getBackground());
		if (newColor != null) {
			this.jButtonLookBGColor.setBackground(newColor);
		}
	}

	/** Try PlaF */
	private void switchLookAndFeel(ActionEvent evt) {
		if (this.onInit) {
			return;
		}
		this.setVisible(false);
		try {
			UIManager.setLookAndFeel((String) this.jComboBoxAllLooks.getSelectedItem());
			SwingUtilities.updateComponentTreeUI(this);
			// this.pack();
			// this.setSize(500, 320);
		} catch (Exception _e) {
			System.out.println("*** Can't set Look'n'Feel!");
		}

		this.setVisible(true);
	}

	/** Exit the Application */
	private void exitForm(WindowEvent evt) {
		// System.exit(0);
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	/*
	 * public static void main(String args[]) { new JTalkerFrontSettings().show(); }
	 */

	public void setVisible(boolean visible) {
		this.setupElements();
		super.setVisible(visible);
	}

	private boolean setupElements() {
		this.jTextFieldServerIP.setText(this.parent.theClient.serverName);
		this.jTextFieldServerPort.setText(String.valueOf(this.parent.theClient.portNum));

		if (this.parent.theClient.useSSL) {
			this.jCheckBoxUseSSL.setSelected(true);
		} else {
			this.jCheckBoxUseSSL.setSelected(false);
		}
		this.jTextFieldUserName.setText(this.parent.theClient.userName);
		String passwd = this.parent.theClient.userPasswd;
		if (this.parent.theClient.savePassword) {
			this.jPasswordFieldPasswd.setText(passwd);
			this.jCheckBoxSavePasswd.setSelected(true);
		} else {
			this.jCheckBoxSavePasswd.setSelected(false);
		}
		this.jTextFieldAppsBrowser.setText(this.parent.theClient.defaultBrowser);
		this.jTextFieldAppsEMailClient.setText(this.parent.theClient.defaultMailer);

		int notificationType = 0;

		for (Enumeration<AbstractButton> e = this.buttonGroupNotification.getElements(); e.hasMoreElements();) {
			JRadioButton tmpButton = (JRadioButton) e.nextElement();
			if (notificationType == this.parent.theClient.newMailNotificationType) {
				tmpButton.setSelected(true);
				break;
			}
			notificationType++;
		}

		if (this.onInit) {
			// Show all available Looks
			UIManager.LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();

			for (int i = 0; i < lfs.length; i++) {
				this.jComboBoxAllLooks.addItem(lfs[i].getClassName());
			}

			this.jComboBoxAllLooks.setSelectedItem(this.parent.theClient.guiPlaf);
		}

		// Chat colors
		this.jButtonLookTXColor.setBackground(Color.decode(this.parent.theClient.guiTextColor));
		this.jButtonLookBGColor.setBackground(Color.decode(this.parent.theClient.guiBgColor));

		// Plugin Directory
		this.jTextFieldPluginDir.setText(this.parent.theClient.pluginDir);

		return true;
	}

	private void showPropertyPanel(int pane) {
		this.jPanelPropsAccount.setVisible(false);
		this.jPanelPropsServer.setVisible(false);
		this.jPanelPropsApps.setVisible(false);
		this.jPanelNotificationApps.setVisible(false);
		this.jPanelLookAndFeel.setVisible(false);
		this.jPanelPlugins.setVisible(false);

		if (pane == 0)
			this.jPanelPropsAccount.setVisible(true);
		else if (pane == 1)
			this.jPanelPropsServer.setVisible(true);
		else if (pane == 2)
			this.jPanelPropsApps.setVisible(true);
		else if (pane == 3)
			this.jPanelNotificationApps.setVisible(true);
		else if (pane == 4)
			this.jPanelLookAndFeel.setVisible(true);
		else if (pane == 5)
			this.jPanelPlugins.setVisible(true);
		else
			return;
	}

	// Variables declaration - do not modify
	private JButton jButtonOK;
	private JButton jButtonCancel;
	private JButton jButton3;
	private JButton jButton4;
	private JCheckBox jCheckBoxSavePasswd;
	private JCheckBox jCheckBoxUseSSL;
	private JLabel jLabelUserName;
	private JLabel jLabelPassword;
	private JLabel jLabelServerName;
	private JLabel jLabelServerPort;
	private JLabel jLabelAppsBrowser;
	private JLabel jLabelAppsEMailClient;
	private JList jListPropertyPages;
	private JPanel jPanelBottom;
	private JPanel jPanelCenter;
	private JPanel jPanelContent;
	private JPanel jPanelPropsAccount;
	private JPanel jPanelPropsServer;
	private JPanel jPanelPropsApps;
	private JPanel jPanelNotificationApps;
	private JPanel jPanelLookAndFeel;
	private JPanel jPanelPlugins;
	private JPasswordField jPasswordFieldPasswd;
	private JScrollPane jScrollPaneProperty;
	private JSplitPane jSplitPaneProperty;
	private JTextField jTextFieldServerIP;
	private JTextField jTextFieldServerPort;
	private JTextField jTextFieldUserName;
	private JTextField jTextFieldAppsBrowser;
	private JTextField jTextFieldAppsEMailClient;
	private ClassLoader cl;
	private ButtonGroup buttonGroupNotification;
	// private ButtonGroup buttonGroupNotificationChat;
	private JLabel jLabelUserListInfo;
	private JPanel jPanelCHATWINDOW;
	private JPanel jPanelUserList;
	private JRadioButton jRadioButtonCHATWINDOWBEEP;
	private JRadioButton jRadioButtonCHATWINDOWNONE;
	private JRadioButton jRadioButtonUserListBeep;
	private JRadioButton jRadioButtonUserListNone;
	private JRadioButton jRadioButtonUserListNotiBox;
	private JRadioButton jRadioButtonUserListToFront;

	private JButton jButtonLookBGColor;
	private JButton jButtonLookTXColor;
	private JComboBox jComboBoxAllLooks;
	private JLabel jLabelLookBGColor;
	private JLabel jLabelLookTXColor;
	private JPanel jPanelLookColors;
	private JPanel jPanelLookPlafs;

	private JTextField jTextFieldPluginDir;
	private JLabel jLabelPluginDir;
	private JButton jButtonPlugins;
	private JButton jButtonPluginDir;

	// End of variables declaration

	/** This class represents a List Row */
	class MyListCellRenderer extends JLabel implements ListCellRenderer {
		private ImageIcon userSettingsIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/user_settings.png"));
		private ImageIcon serverSettingsIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/server.png"));
		private ImageIcon appsSettingsIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/apps.png"));
		private ImageIcon notificationIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/notification.png"));
		private ImageIcon lookIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/look.png"));
		private ImageIcon pluginIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/plugins.png"));

		// This is the only method defined by ListCellRenderer.
		// We just reconfigure the JLabel each time we're called.

		public Component getListCellRendererComponent(JList list, Object value, // value to display
				int index, // cell index
				boolean isSelected, // is the cell selected
				boolean cellHasFocus) // the list and the cell have the focus
		{
			if (value == null) {
				return null;
			}
			String rowText = (String) value;

			if (rowText.equals("Login")) {
				this.setIcon(this.userSettingsIcon);
			} else if (rowText.equals("Server")) {
				this.setIcon(this.serverSettingsIcon);
			} else if (rowText.equals("Apps")) {
				this.setIcon(this.appsSettingsIcon);
			} else if (rowText.equals("Notification")) {
				this.setIcon(this.notificationIcon);
			} else if (rowText.equals("Look")) {
				this.setIcon(this.lookIcon);
			} else if (rowText.equals("Plugins")) {
				this.setIcon(this.pluginIcon);
			}
			this.setText(rowText + "  ");

			if (isSelected) {
				this.setBackground(list.getSelectionBackground());
				this.setForeground(list.getSelectionForeground());
			} else {
				this.setBackground(list.getBackground());
				this.setForeground(list.getForeground());
			}

			this.setEnabled(list.isEnabled());
			this.setFont(list.getFont());
			this.setOpaque(true);

			return this;
		}
	}
}
